package com.suguowen.sblog.util;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class MyFileUtil {

    // location:src/main/resources/static/editor.md-master/examples/test.md
    // 文件读取教程https://blog.csdn.net/Diamond_Tao/article/details/80010225
    // 读取文件内容
    public static String getContent4File(String location) {
        File file = new File(location);
        String content = "";
        try {
            content = FileUtils.readFileToString(file, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content;
    }

    // 保存内容到指定文件
    public static void setContent2File(String location, String content) {
        FileWriter writer;
        try {
            writer = new FileWriter(location);
            writer.write(content);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
